package org.example.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class TestCopy {
    public static void main(String[] args) throws Exception{
        File file = new File("D:\\tmp\\111.txt");
        File path = new File("D:\\tmp\\222.txt");

        //创建输入流
        FileInputStream stream = new FileInputStream(file);
        //创建输出流
        FileOutputStream outputStream = new FileOutputStream(path);

        //需要写入的数据
        StringBuilder builder =new StringBuilder();

        //读取数据
        byte[] bytes = new byte[1024];
        while (true){
            int read = stream.read(bytes);
            builder.append(new String(bytes,0,read));
            if(read<bytes.length){
                break;
            }
        }

        //写入文件
        outputStream.write(builder.toString().getBytes());

        //关闭流
        stream.close();
        outputStream.close();
    }
}
